package com.qixin.util.chargeInterfce.QiXinPublic;

import com.qixin.util.chargeInterfce.Charge.Test;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Zhang on 2018/10/21.
 * 星星充电接口调用
 */
public class StarInterFce {
    public  static  void main(String [] args){
        //查询
      // StarInterFce starInterFce=new StarInterFce();
       //  String token=starInterFce.getToken();
      // System.err.println(starInterFce.findUseCharge(token, "313744932123456789112345679"));
        // 停止
       StarInterFce starInterFce=new StarInterFce();
       String token=starInterFce.getToken();
      System.err.println(starInterFce.stopCharge(token, "313744932622764866892784604","12000000000000090000318002")); ;

   //启动
   /*    StarInterFce starInterFce=new StarInterFce();
          String token=starInterFce.getToken();
    System.err.println(starInterFce.useCharge(token, "313744932123456789112345672","11000000000000090000342000",null));
*/    }

    /**
     *充电桩信息查询
     * @param token  运营商获取的令牌
     * @param LastQueryTime 上次查询时间  格式“yyyy-MM-dd HH:mm:ss”，可以为空，如果不填写，则查询所有的充电站信息
     * @param PageNo  查询页码   	整型	不填写默认为1
     * @param PageSize 每页数量	 整型	不填写默认为10
     */
    public  String getChargeQuery(String token,String LastQueryTime,Integer  PageNo,Integer PageSize){
        // 通过token获得数据
        Map<String, Object> stationParams = new HashMap<String, Object>();
        stationParams.put("LastQueryTime", LastQueryTime);
        stationParams.put("PageNo", PageNo);
        stationParams.put("PageSize", PageSize);
        // 获取电站信息
        String stationInfo = null;
        try {
            stationInfo = Test.getResultFromDxpApi(stationParams, "query_stations_info", token);
        } catch (Exception e) {
            e.printStackTrace();
        }
   return  stationInfo;
    }

    /**
     *
     * @param token 令牌
     * @param StationIDs   充电站ID 可批量查询  数组
     * @return  返回出充电设备接口状态JSON
     */
    public  String getChargState(String token,String[] StationIDs){
        // 通过token获得数据
        Map<String, Object> stationParams = new HashMap<String, Object>();
        stationParams.put("StationIDs",StationIDs);
        String result = null;
        try {
            result = Test.getResultFromDxpApi(stationParams, "query_station_status", token);
        } catch (Exception e) {
            e.printStackTrace();
        }
       return  result ;
    }

    /**
     * 检测设备
     * @param token
     * @param EquipAuthSeq 运营商ID+唯一自定义  需要共28位字符串
     * @param ConnectorID  充电枪ID
     * @return
     */
    public  String checkCharge(String token ,String EquipAuthSeq,String ConnectorID){
        // 通过token获得数据
        Map<String, Object> stationParams = new HashMap<String, Object>();
        stationParams.put("EquipAuthSeq",EquipAuthSeq);
        stationParams.put("ConnectorID",ConnectorID);
        String result = null;
        try {
            result = Test.getResultFromDxpApi(stationParams, "query_equip_auth", token);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  result ;
    }

    /**
     * 启动充电
     * @param token
     * @param StartChargeSeq 运营商ID+唯一自定义   需要共28位字符串
     * @param ConnectorID 充电枪ID
     * @param QRCode 二维码
     * @return
     */
    public  String useCharge(String token ,String StartChargeSeq,String ConnectorID,String QRCode){
        // 通过token获得数据
        Map<String, Object> stationParams = new HashMap<String, Object>();
        stationParams.put("StartChargeSeq",StartChargeSeq);
        stationParams.put("ConnectorID",ConnectorID);
        stationParams.put("QRCode",QRCode);
        String result = null;
        try {
            result = Test.getResultFromDxpApi(stationParams, "query_start_charge", token);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  result ;
    }

    /**
     * 查询已启动的充电桩状态
     * @param token  令牌
     * @param StartChargeSeq   订单号  运营商ID+唯一自定义   需要共28位字符串
     * @return
     */
    public  String findUseCharge(String token , String StartChargeSeq ){
        // 通过token获得数据
        Map<String, Object> stationParams = new HashMap<String, Object>();
        stationParams.put("StartChargeSeq",StartChargeSeq);
        String result = null;
        try {
            result = Test.getResultFromDxpApi(stationParams, "query_equip_charge_status", token);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  result ;
    }

    /**
     * 停止充电
     * @param token
     * @param StartChargeSeq
     * @return
     */
    public  String stopCharge(String token , String StartChargeSeq,String  ConnectorID ){
        // 通过token获得数据
        Map<String, Object> stationParams = new HashMap<String, Object>();
        stationParams.put("StartChargeSeq",StartChargeSeq);
        stationParams.put("ConnectorID",ConnectorID);
        String result = null;
        try {
            result = Test.getResultFromDxpApi(stationParams, "query_stop_charge", token);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  result ;
    }

    /**
     *获取token令牌

     * @return  获取到的TOKEN
     */
    public  String  getToken(/*String OperatorID,String OperatorSecret*/){
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("OperatorID",Test.SERVER_OPERATORID );
        params.put("OperatorSecret", Test.SERVER_OPERATOR_SECRET);
        try {
            return   Test.getResultFromDxpApi(params, "query_token", null);
        } catch (Exception e) {
            e.printStackTrace();
           System.err.println("TOKEN获取失败");
        }
        return null;
    }
}
